export default {
  check(formData, rule) {
    for (let i = 0; i < rule.length; i++) {
      const item = rule[i];
      const value = formData[item.name];
      if (item.checkType === "string") {
        const [min, max] = item.checkRule.split(",");
        if (value.length < min || value.length > max) {
          this.error = item.errorMsg;
          return false;
        }
      } else if (item.checkType === "in") {
        const options = item.checkRule.split(",");
        if (!options.includes(value)) {
          this.error = item.errorMsg;
          return false;
        }
      } else if (item.checkType === "notnull") {
        if (!value || (Array.isArray(value) && value.length === 0)) {
          this.error = item.errorMsg;
          return false;
        }
      }
    }
    return true;
  },
  error: ""
};